<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Deliverorder extends CI_Controller {

    /**
     * 订单交运  燕文 云途 邮政
     * Index Page for this controller.
     *
     * Maps to the following URL
     * 		http://example.com/index.php/welcome
     *	- or -
     * 		http://example.com/index.php/welcome/index
     *	- or -
     * Since this controller is set as the default controller in
     * config/routes.php, it's displayed at http://example.com/
     *
     * So any other public methods not prefixed with an underscore will
     * map to /index.php/welcome/<method_name>
     * @see https://codeigniter.com/user_guide/general/urls.html
     */
    function __construct()
    {
        parent::__construct();
        $this->load->model('Function_m','fun');
        $this->load->model('Deliverorder_m','m');
        $this->load->model('Order_m','order');  //订单模型
        $this->pageSize =$this->config->item('pagenum');
    }
    /*********
     *** 订单设置
     *** //
     ****************/
    public function orderset()
    {
        $rsdb = $this->fun->getconfig();
        $this->tpl->assign("rsdb",$rsdb);
        $this -> tpl -> display("order/syscenter.tpl");
    }
	
	/***************
	***
	*** 速卖通无忧物流
	******************/
    public function aliexpressOrder()
	{
		$this->emsExpress(9);
		 //$this->tpl->display("order/aliexpressOrder.tpl");
	}
    // 燕文 云途 邮政等交运
    public function emsExpress($orderType=6)
    {
        $nowpage = $_REQUEST["pageid"];
        if ($nowpage == "")
            $nowpage = 1;
        $where = " and orderType =".$orderType;
        if($this->input->get('orderType')){
            $where = " and orderType =".$this->input->get('orderType');
        }
        $isexe = $this->input->get('isexe');
        $this->tpl->assign("isexe",$isexe);
        if($isexe==3){
            $where.=" AND isexe = 0";
        }elseif($isexe==4){
            $where.=" AND isexe = 3";
        }else{
            if(!$isexe){
            }else{
                $where.=" AND isexe = $isexe";
            }
        }
        $other = $this->input->get('other');
        if($other)
        {
            $where.=" AND (orderID = '".$other."' or mailNo = '".$other."')";
            $this->tpl->assign("other",$other);
        }

        $starttime = trim($this->input->get('starttime'));
        if($starttime)
        {
            $times = $starttime." 00:00:00";
            $where.=" AND (mailinstime >= '".strtotime($times)."')";
            $this->tpl->assign("starttime",$starttime);
        }

        $endtime = trim($this->input->get('endtime'));
        if($endtime)
        {
            $times = $endtime." 23:59:59";
            $where.=" AND (mailinstime <= '".strtotime($times)."')";
            $this->tpl->assign("endtime",$endtime);
        }
        $statusst = $this->input->get('statusst');
        if($statusst)
        {
            if($statusst==1)
            {
                $status ='已支付';
            }
            if($statusst==2)
            {
                $status ='配货中';
            }
            if($statusst==3)
            {
                $status ='已完成';
            }
            $where.=" AND statusst = '".$status."'";
            $this->tpl->assign("statusst",$statusst);
        }
        //发货方式
        $deliver = $this->input->get('deliver');
        if($deliver){
            $where.=" AND deliver = '".$deliver."'";
            $this->tpl->assign("deliver",$deliver);
        }
        $list = $this->fun->getalllist('db_mabangorder',$where,$nowpage,$if_csv,$this->pageSize);
        //echo $this->db->last_query();exit;
        foreach($list["list"] as $key=>$rs)
        {
            if($rs["mailinstime"])$list["list"][$key]["mailinstime"] = date("Y-m-d H:i:s",$rs["mailinstime"]);
        }
        $pageList = $this->pagenav->page($list["total"], $nowpage, $this->pageSize);
        $this->tpl->assign("totalpage", ceil($list["total"] / $this->pageSize));
        $this->tpl->assign("total", $list["total"]);
        $this->tpl->assign("pageList", $pageList);
        $this->tpl->assign("department", $_COOKIE["department"]);
        $this->tpl->assign("orderlist",$list["list"]);
        $this->tpl->assign("orderType",$orderType);
        if($orderType==8){ //e邮宝线下上海
            $this->tpl->display("order/emsexpress.tpl");
        }elseif ($orderType==7){ //燕文
            $this->tpl->display("order/yanwenexpress.tpl");
        }elseif ($orderType==9){ //无忧物流
           $this->tpl->display("order/aliexpressOrder.tpl");
        }elseif ($orderType==11){ //cnpost
            $this->tpl->display("order/cnpostexpress.tpl");
        }elseif ($orderType==13){ //欧速通
            $this->tpl->display("order/ostexpress.tpl");
        }else{
            //$orderType 6 默认 云途
            $this->tpl->display("order/yuntuexpress.tpl");
        }

    }
    public function ajaxbutton()
    {
        $op = $_REQUEST["op"];
        /*******************************
         *** 自动e邮宝线上交运
         ******************************/
        if($op =='cnpostexpress')
        {
            $res = $this->m->getcnpostExpress();
            echo $res["str"];
            echo "<meta http-equiv=\"refresh\" content=\"1; url=/deliverorder/ajaxbutton?op=cnpostexpress\">";
        }
        //二次交运cnpost
        if($op =='secondcnpostexpress')
        {
            $res = $this->m->getsecondcnpostExpress();
            echo $res["str"];
            echo "<meta http-equiv=\"refresh\" content=\"1; url=/deliverorder/ajaxbutton?op=secondcnpostexpress\">";
        }
        //二次交运cnpost 无远程了 全部放在本地了
        /**
        if($op =='remotecnpostexpress')
        {
            $res = $this->m->remotecnpostexpress();
        }**/
        /*******************************
     *** 自动交运燕文
     ******************************/
        if($op =='yanwenexpress')
        {
            //new add 2017/7/6
            $orderlist = trim($this->input->post('orderlist'));

            //如果获取到的订单来源为马帮
            if($this->input->post('isformMabang') ==1)
            {
                $this->load->library('Mabang');
                $deliver = $this->input->post('deliver'); //发货方式
                $res= $this->mabang->savemabangorderlist($orderlist,7,$deliver); //燕文orderType 7
            } // new add end

            $res = $this->m->getyanwenexpress();
            echo $res["str"];
            echo "<meta http-equiv=\"refresh\" content=\"1; url=/deliverorder/ajaxbutton?op=yanwenexpress\">";
        }
        //云途模板文件
		if($op  =='expresstemplates')
		{
			 $this->tpl->display("order/expresstemplates.tpl",0,0,1);
		}
        /*******************************
            *** 自动交运云途
     ******************************/
        if($op =='yuntuexpress')
        {
            $res = $this->m->getyuntuexpress();
            echo $res["str"];
            echo "<meta http-equiv=\"refresh\" content=\"1; url=/deliverorder/ajaxbutton?op=yuntuexpress\">";
        }
        /*******************************
         *** 自动交运 欧速通
         ******************************/
        if($op =='ostexpress')
        {
            $res = $this->m->getostexpress();
            echo $res["str"];
            echo "<meta http-equiv=\"refresh\" content=\"1; url=/deliverorder/ajaxbutton?op=ostexpress\">";
        }
        /*******************************
         *** 自动交运E邮宝
         ******************************/
        if($op =='emsexpressPro')
        {
            $res = $this->m->getemsexpressPro();
            echo $res["str"];
            echo "<meta http-equiv=\"refresh\" content=\"1; url=/deliverorder/ajaxbutton?op=emsexpressPro\">";
        }
		
        if($op == 'saveyanwenexpress')
        {
            /********************************************
             * 订单相关设置中保存yanwenexpress
             ***********************************************/
            $post["yanwen_userid"]  = $this->input->post("yanwen_userid");
            $post["yanwen_pass"]  = $this->input->post("yanwen_pass");
           // $post["yanwen_currency"]  = $this->input->post("yanwen_currency");
            $post["yanwen_apiurl"]  = $this->input->post("yanwen_apiurl");
            //$post["yanwen_channel"]  = $this->input->post("yanwen_channel");
            //$orderType = $this->input->post('orderType');
            //$arr_data = array('searialize'=>serialize($post),'orderType'=>$orderType);
            $arr_data = array('searialize'=>serialize($post));
            echo json_encode($arr_data);
            //echo serialize($post);
            exit;
        }
        //保存相关交运配置
        if($op == 'getyanwenexpress')
        {
            /********************************************
             * 订单相关设置中读取yanwenexpress
             ***********************************************/
            $res = $this->fun->getdatabasesdetail("web_config"," AND c_key = '".$this->input->post_get("ckey")."'");
            //echo $this->db->last_query();exit;
           // $orderType = $this->input->post_get('orderType');
            if($res["c_value"])
            {
                $arr_c_value = unserialize($res["c_value"]);
                //$arr_c_value['orderType'] = $orderType;
                echo json_encode($arr_c_value);
                exit;
            }else{
            }
        }
        /********************************************
         * 保存交运信息
         **string type :"yanwen";"yuntu" ;"ems" ;"cnpost"
         **string orderlist    此处并未实际交运，仅保存需要交运的信息
         ***********************************************/
        if($op=='saveexpress'){
			
            $res = $this->m->saveexpress();  //$res 为交运类型 暂定
            if($res)
            {
                //开始自动交运
                if($res==7){ //燕文
                    header("location:/deliverorder/ajaxbutton?op=yanwenexpress");
                }
                if($res==6){  //云途
                    header("location:/deliverorder/ajaxbutton?op=yuntuexpress");
                }
                if($res==8){  //E邮宝
                    //header("location:/deliverorder/ajaxbutton?op=emsexpress");
					header("location:/deliverorder/emsExpress/8");
                }
                if($res==11){  //E邮宝线上
                    header("location:/deliverorder/ajaxbutton?op=cnpostexpress");
                }
                if($res==13){  //欧速通
                    header("location:/deliverorder/ajaxbutton?op=ostexpress");
                }


            }

        }
        //保存配置信息
        if($op == 'saveemsexpress')
        {
            /********************************************
             * 订单相关设置中保存emsexpress
             ***********************************************/
            $post["e_company"]  = $this->input->post("e_company");
            $post["e_alias"]  = $this->input->post("e_alias");
            $post["e_username"]  = $this->input->post("e_username");
            $post["e_phone"]  = $this->input->post("e_phone");
            $post["e_mobile"]  = $this->input->post("e_mobile");
            $post["e_address"]  = $this->input->post("e_address");
            $post["e_country"]  = $this->input->post("e_country");
            $post["e_city"]  = $this->input->post("e_city");
            $post["e_postcode"]  = $this->input->post("e_postcode");
            $post["e_countrycode"]  = $this->input->post("e_countrycode");
            $post["e_version"]  = $this->input->post("e_version");
            $post["e_token"]  = $this->input->post("e_token");
            $post["e_url"]  = $this->input->post("e_url");
            $post["e_email"]  = $this->input->post("e_email");
            $post["e_province"]  = $this->input->post("e_province");
            $post["e_area"]  = $this->input->post("e_area");
            $post["e_accounttype"]  = $this->input->post("e_accounttype");
            echo serialize($post);
            exit;
        }
        //保存配置信息 e邮宝线下上海
        if($op == 'saveeofflineexpress')
        {
            /********************************************
             * 订单相关设置中保存eofflineexpress
             ***********************************************/
            $post["eoffline_company"]  = $this->input->post("eoffline_company");
            $post["eoffline_alias"]  = $this->input->post("eoffline_alias");
            $post["eoffline_username"]  = $this->input->post("eoffline_username");
            $post["eoffline_phone"]  = $this->input->post("eoffline_phone");
            $post["eoffline_mobile"]  = $this->input->post("eoffline_mobile");
            $post["eoffline_address"]  = $this->input->post("eoffline_address");
            $post["eoffline_country"]  = $this->input->post("eoffline_country");
            $post["eoffline_city"]  = $this->input->post("eoffline_city");
            $post["eoffline_postcode"]  = $this->input->post("eoffline_postcode");
            $post["eoffline_countrycode"]  = $this->input->post("eoffline_countrycode");
            $post["eoffline_version"]  = $this->input->post("eoffline_version");
            $post["eoffline_token"]  = $this->input->post("eoffline_token");
            $post["eoffline_url"]  = $this->input->post("eoffline_url");
            $post["eoffline_email"]  = $this->input->post("eoffline_email");
            $post["eoffline_province"]  = $this->input->post("eoffline_province");
            $post["eoffline_area"]  = $this->input->post("eoffline_area");
            $post["eoffline_accounttype"]  = $this->input->post("eoffline_accounttype");
            echo serialize($post);
            exit;
        }
        //保存配置信息aspcnpost
        if($op == 'savecnpostexpress')
        {
            /********************************************
             * 订单相关设置中保存cnpostexpress
             ***********************************************/
            $post["cnpost_alias"]  = $this->input->post("cnpost_alias");
            $post["cnpost_username"]  = $this->input->post("cnpost_username");
            $post["cnpost_phone"]  = $this->input->post("cnpost_phone");
            $post["cnpost_enaddress"]  = $this->input->post("cnpost_enaddress");
            $post["cnpost_cnaddress"]  = $this->input->post("cnpost_cnaddress");
            $post["cnpost_city"]  = $this->input->post("cnpost_city");
            $post["cnpost_postcode"]  = $this->input->post("cnpost_postcode");
            $post["cnpost_countrycode"]  = $this->input->post("cnpost_countrycode");
            $post["cnpost_version"]  = $this->input->post("cnpost_version");
            $post["cnpost_token"]  = $this->input->post("cnpost_token");
            $post["cnpost_url"]  = $this->input->post("cnpost_url");
            $post["cnpost_email"]  = $this->input->post("cnpost_email");
            $post["cnpost_province"]  = $this->input->post("cnpost_province");
            $post["cnpost_area"]  = $this->input->post("cnpost_area");
            $post["cnpost_fax"]  = $this->input->post("cnpost_fax");
            echo serialize($post);
            exit;
        }
        //保存配置信息
        if($op == 'saveyuntuexpress')
        {
            /********************************************
             * 订单相关设置中保存yuntuexpress
             ***********************************************/
            $post["y_company"]  = $this->input->post("y_company");
            $post["y_xing"]  = $this->input->post("y_xing");
            $post["y_phone"]  = $this->input->post("y_phone");
            $post["y_mobile"]  = $this->input->post("y_mobile");
            $post["y_address"]  = $this->input->post("y_address");
            $post["y_city"]  = $this->input->post("y_city");
            $post["y_postcode"]  = $this->input->post("y_postcode");
            $post["y_countrycode"]  = $this->input->post("y_countrycode");
            $post["y_version"]  = $this->input->post("y_version");//客户编号
            $post["y_token"]  = $this->input->post("y_token");
            $post["y_url"]  = $this->input->post("y_url");
            $post["y_name"]  = $this->input->post("y_name");
            $post["y_province"]  = $this->input->post("y_province");
            echo serialize($post);
            exit;
        }
        /**********同步燕文订单信息***/
        if($op=="dodistribution")
        {
            //$id = trim($this->input->post('str'),",");
            //$inid = explode(",",$id);
			
			$id = substr($this->input->post('str'),0,-1);
            $inid = explode(",",$id);
			$this->db->where_in('id', $inid);
			$this->db->order_by('id', 'DESC');
			$orderinfo = $this->db->get('db_mabangorder')->result_array();
		
            foreach($orderinfo as $key=>$rsdb)
            {
                if($rsdb["statusst"] =='已支付' && $rsdb["isexe"] ==1){
					if($rsdb["isform"] ==1)	//马帮的订单
					{

						if($rsdb["statusst"] =='已支付'){
							$postdata["statusst"] = '配货中';
							$this->db->trans_begin();
							$this->db->query($this->db->update_string('db_mabangorder', $postdata, 'orderID=' .$rsdb["orderID"]));
							if($rsdb["orderType"]==5)
							{
								$expressTitle = 'UBI澳洲';
								$expressID = 29;
								$rsdb["orderID"]=str_replace("\n","",$rsdb["orderID"]);
								$rsdb["orderID"]=str_replace("\r","",$rsdb["orderID"]);
								$rsdb["orderID"]=str_replace("\r\n","",$rsdb["orderID"]);
								$this->load->library('Mabang');
								$this->mabang->updateordersfexpress($rsdb["orderID"],$rsdb["mailNo"],$expressTitle,$expressID);
							}
							if($rsdb["orderType"]==9)
							{
								$expressTitle = '无忧物流';
								$expressID = 53;
								$this->load->library('Mabang');
								$rsdb["orderID"]=str_replace("\n","",$rsdb["orderID"]);
								$rsdb["orderID"]=str_replace("\r","",$rsdb["orderID"]);
								$rsdb["orderID"]=str_replace("\r\n","",$rsdb["orderID"]);
								$this->mabang->updateordersfexpress($rsdb["orderID"],$rsdb["mailNo"],$expressTitle,$expressID);
							}
                            if($rsdb["orderType"]==7)   //燕文
                            {
                                $expressTitle = '燕文';
                                if($rsdb['deliver']=="中邮上海平邮小包"){
                                    $expressID = 12;
                                }elseif($rsdb['deliver']=="中邮上海挂号小包"){
                                    $expressID = 11;
                                }else{
                                    $expressID = 15; //燕文专线
                                }
                                $this->load->library('Mabang');
								$rsdb["orderID"]=str_replace("\n","",$rsdb["orderID"]);
								$rsdb["orderID"]=str_replace("\r","",$rsdb["orderID"]);
								$rsdb["orderID"]=str_replace("\r\n","",$rsdb["orderID"]);
                                $this->mabang->updateordersfexpress(trim($rsdb["orderID"]),$rsdb["mailNo"],$expressTitle,$expressID);
                            }

							if ($this->db->trans_status() === FALSE)
							{
								$this->db->trans_rollback();
							}
							else
							{
								$this->db->trans_commit();
							}
							
						}
					
					}else{
                    //更新日志记录
                    $sql = "SELECT * FROM db_order_list WHERE order_sn = '{$rsdb["orderID"]}' ";
                    $rs = $this->db->query($sql)->row_array();
                    //只能已支付状态才能配货
                     if($rs['order_status']==2){
                         $postdata["statusst"] = '配货中';
                         $orderdata['order_status'] = 3; //状态位配货中
                         $this->db->update('db_mabangorder', $postdata, 'orderID=' ."'{$rsdb["orderID"]}'");
                         $this->db->update('db_order_list', $orderdata, 'order_sn=' ."'{$rsdb["orderID"]}'");

						 if(count($rs)>0){
							$imgdata["goods_id"] = $rs['order_id'];	//订单ID db_order_list
							$imgdata["updatetime"] = date("Y-m-d H:i:s");
							$imgdata["createUid"] = $_COOKIE['userid'];
							$imgdata["types"] = 3;
							$imgdata["content"] = '标配货,交易ID='.$rs['tradeid'].",运单号=".$rsdb['mailNo'];
							$imgdata["createUser"] =$_COOKIE['username'];
							$this->db->insert('db_goods_log', $imgdata);
						   }
                     }else{
                         if($rs['order_status']==1){
                             $postdata["statusst"] = '新订单';
                         }
                         if($rs['order_status']==3){
                             $postdata["statusst"] = '配货中';
                         }
                         if($rs['order_status']==4){
                             $postdata["statusst"] = '订单已发货';
							 $postdata["haveWrong"] = 1;
                         }
                         if($rs['order_status']==5){
                             $postdata["statusst"] = '订单已完成';
							 $postdata["haveWrong"] = 1;
                         }
                         if($rs['order_status']==6){
                             $postdata["statusst"] = '订单已作废';
							 $postdata["haveWrong"] = 1;
                         }
                         if($rs['order_status']==7){
                             $postdata["statusst"] = '待审查';
							 $postdata["haveWrong"] = 1;
                         }
                         $this->db->update('db_mabangorder', $postdata, 'orderID=' ."'{$rsdb["orderID"]}'");
                     }
                    
					}
                }
            }
            echo 200;
            die;

        }
        if($op=='yanwenexpressurl')
        {

            $id = $this->input->get('id');
            /***************************
             *** UPS 标签打印
             ****************************/
            if($this->input->get('orderType') == 7)
            {
                if(strpos($id,',') === false){
                    echo 1;
                }else{
                    $id = substr($id,0,-1);
                    $inid = explode(",",$id);
                    $this->db->where_in('id', $inid);
                    $this->db->order_by('id', 'DESC');
                    $orderinfo = $this->db->get('db_mabangorder')->result_array();

                    if(count($orderinfo)){
                        foreach($orderinfo as $key=>$rs)
                        {

                            $rsOrder = $this->fun->getdatabasesdetail('db_order_list'," AND order_sn='".$rs["orderID"]."'");
                            if($rsOrder)
                            {
                                $goodslist = $this->db->get_where('db_order_sell',"order_id ='".$rsOrder["order_id"]."'")->result_array();
                                foreach($goodslist as $sd =>$goods)
                                {
                                    $stock = $this->fun->getdatabaseslist('db_goods_stock'," AND goods_id='".$goods["goods_id"]."'");
                                    $goodslist[$sd]["stock"] = $stock;
                                }
                                $orderinfo[$key]["shopname"] = $rsOrder["shopname"];
                                $orderinfo[$key]["shopoper"] = $rsOrder["shopoper"];
                                $orderinfo[$key]["tradeid"] = $rsOrder["tradeid"];
                                $orderinfo[$key]["remark"] = $rsOrder["remark"];
                                $orderinfo[$key]["goodslist"] = $goodslist;
                            }
                            
                        }
                        $this->tpl->assign("orderinfo",$orderinfo);
                        $this->tpl->display("order/upsexpressmoreurl.tpl",0,0,1);//打印燕文标签信息
                    }
                }

            }

        }
        if ($op == "delone") {
            if ($this->input->post('st') == "delyanwenexpress") {
                $res = $this->db->select()->from('db_mabangorder')->where('id=' . $this->input->post('id'))->get()->result_array();

                $this->db->delete('db_mabangorder', 'id=' . $this->input->post('id'));
                $res = array("txt" => 200, "url" => '/deliverorder/yanwenexpress/7');
                echo json_encode($res);
                die;
            }
            if ($this->input->post('st') == "delyuntuexpress") {
                $res = $this->db->select()->from('db_mabangorder')->where('id=' . $this->input->post('id'))->get()->result_array();

                $this->db->delete('db_mabangorder', 'id=' . $this->input->post('id'));
                $res = array("txt" => 200, "url" => '/deliverorder/yuntuexpress/6');
                echo json_encode($res);
                die;
            }
            if ($this->input->post('st') == "delemsexpress") {
                $res = $this->db->select()->from('db_mabangorder')->where('id=' . $this->input->post('id'))->get()->result_array();

                $this->db->delete('db_mabangorder', 'id=' . $this->input->post('id'));
                $res = array("txt" => 200, "url" => '/deliverorder/emsexpress/8');
                echo json_encode($res);
                die;
            }
            if ($this->input->post('st') == "delostexpress") {
                $res = $this->db->select()->from('db_mabangorder')->where('id=' . $this->input->post('id'))->get()->result_array();

                $this->db->delete('db_mabangorder', 'id=' . $this->input->post('id'));
                $res = array("txt" => 200, "url" => '/deliverorder/yanwenexpress/13');
                echo json_encode($res);
                die;
            }

        }
		if($op == 'showAliaddressconfig')
		{
			 $shoplist =  $this->db->get_where("d_shop", " platfrom  = '10' AND del_flag = 0")->result_array();
			 if(count($shoplist)>0)
			{
				foreach($shoplist as $key=>$rs)
				{
					 $shoplist[$key]["aliexpressData"] = unserialize($rs["aliexpressData"]);
				}
			}
			 $this->tpl->assign("shoplist",$shoplist);
			 $this->tpl->display("order/showAliaddressconfig.tpl");//打印燕文标签信息
		}
		if($op =='saveAliaddressconfig')
		{
			$shopID = $this->input->post('shopid');
			$aliexpressBackData = $this->input->post();
			unset($aliexpressBackData["shopid"]);
			unset($aliexpressBackData["_post_type"]);
			$aliexpressdata = serialize($aliexpressBackData);
			$this->db->update("d_shop",array("aliexpressData"=>$aliexpressdata),"id='".$shopID."'");
			 $this->fun->phpalert(4, "", '', "/deliverorder/ajaxbutton?op=showAliaddressconfig");

		}
        //导入pdf文件处理
        if($op == "importPdfFile"){
            $mabang_id = trim($this->input->post("mabang_id"));
            $arr_mabang =$this->db->get_one("select * from db_mabangorder where id='{$mabang_id}'");
            if(!$arr_mabang){
                echo "参数错误，请联系管理员解决!";exit;
            }
            $deliver_num = trim($this->input->post("deliver_num"));
            $arr_excel_file = $_FILES['upfile'];
            if(!empty($arr_excel_file)&&$arr_excel_file['error']==0){
                $fileName = $arr_excel_file["name"];
                $tmpFileName = $arr_excel_file["tmp_name"];
                //扩展名判断
                $fileExtName = explode(".",$fileName);
                $extName = $fileExtName[count($fileExtName)-1];
                if(!($extName=="pdf")){
                    echo "上传的文件扩展名应该为.pdf";exit;
                }
                $arr_post_data = array();
                $label_pdf_content = file_get_contents($tmpFileName);
                $dir = dirname(__FILE__) . "/../../uploads/wuyouexpress/".date("Ymd");
                !is_dir($dir) && @mkdir($dir, 0755, true);
                $Path_mailNo = $dir. "/".$deliver_num."_mailno.pdf";
                if(file_put_contents($Path_mailNo, $label_pdf_content)>0){
                    $pathst = str_replace(dirname(__FILE__) . "/../../", '',$Path_mailNo);
                    $arr_post_data["printUrl"] = $pathst;  //pdf格式文件地址

                    $rsdbts = $this->m->pdf2png($Path_mailNo,"wuyouexpress");
                    if(!empty($rsdbts[0])){
                        $image_urls=implode(",",$rsdbts);
                    }else{
                        $image_urls = $rsdbts[0];
                    }
                }
               $arr_post_data["print_img"] = $image_urls;
                $arr_post_data['isexe'] = 1;
                $arr_post_data['exememo'] = "pdf上传成功";
                $arr_post_data['mailNo'] = $deliver_num;
                $arr_post_data["mailinstime"] =time();
                $this->db->update('db_mabangorder', $arr_post_data, 'id=' .$mabang_id);


                $update_order = "";
                $update_order["shipping_number"] = $deliver_num;	//运单号
                $update_order["shipping_time"] = time();				//交运时间
                $update_order["shipping_name"] = "无忧物流";
                $shipping =$this->db->get_one("select * from db_order_express where name='无忧物流'");
                $update_order["shipping_id"] = $shipping["id"]?$shipping["id"]:22;
                $this->db->update('db_order_list', $update_order, 'order_sn=' .$arr_mabang["orderID"]);
                //var_dump($arr_body_express);exit;
                //更新日志记录
                $arr_order_list =$this->db->get_one("select * from db_order_list where order_sn='{$arr_mabang['orderID']}'");
                $imgdata = "";
                $imgdata["goods_id"] = $arr_order_list["order_id"];	//订单ID db_order_list
                $imgdata["updatetime"] = date("Y-m-d H:i:s");
                $imgdata["createUid"] = $_COOKIE['userid'];
                $imgdata["types"] = 3;
                $imgdata["content"] = 'pdf上传成功,交易ID='.$arr_order_list['tradeid'].",运单号：".$deliver_num;
                $imgdata["createUser"] =$_COOKIE['username'];
                $this->db->insert('db_goods_log', $imgdata);

               echo 200;exit;

            }else{
                echo "未上传任何文件";exit;
            }




        }
    }





}
